<?php
/**
 * Created by PhpStorm.
 * User: rentvogue
 * Date: 2017/8/15
 * Time: 下午6:16
 */

namespace Protocols;

/**
 * mysql json 协议
 * @author Zhangyouliang<1577121881@qq.com>
 * @package Protocols
 */
class JsonMySQL
{
    public static function input($recv_buffer)
    {
        $buffer_len = strlen($recv_buffer);
        if ($buffer_len < 0) {
            return 0;
        }
        return $buffer_len;
    }

    public static function decode($recv_buffer)
    {
        $package_data = json_decode(trim($recv_buffer), true);
        $mysql_sql = $package_data['sql'];
        return array(
            'sql' => $mysql_sql,
            'time' => time()
        );
    }

    /**
     * 将服务器的send 的数据原样子放回给客户端
     * @param $data
     * @return mixed
     */
    public static function encode($data)
    {
        return $data;
    }
}